package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 广告错误异常枚举类
 */
public enum AdException implements IntegerEnum<Integer> {

    AD_NOT_EXIST(50201, "广告不存在"),
    AD_LOCATION_NOT_EXIST(50202, "广告位不存在"),
    CURRENT_SHOP_NOT_OPERATION(50203, "当前商家不能操作"),
    PARAMETER_NOT_NUll(50204, "参数值不能为空"),
    AD_MARK_CODE_NOT_REPETITION(50205, "广告位置已存在广告位，请勿重复添加"),
    AD_LOCATION_NOT_DEL(50206, "该广告位下已有广告，不能被删除"),
    ;


    private Integer code;

    private String msg;

    AdException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @JsonCreator
    public static AdException getByCode(int code) {
        for (AdException value : AdException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
